package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.WpPermissionsDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.service.WpPermissionsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = WpPermissionsService.class)
@Transactional
public class WpPermissionsServiceImpl implements WpPermissionsService{

    @Autowired
    private WpPermissionsDao wpPermissionsDao;


    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<Permission> permissions  =wpPermissionsDao.selectByCondtion(queryPageBean.getQueryString());
        PageInfo<Permission> pageInfo = new PageInfo<>(permissions);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }


    @Override
    public void save(Permission permission) {
        wpPermissionsDao.add(permission);
    }


    @Override
    public Permission findById(Integer id) {
        return wpPermissionsDao.findById(id);
    }

    @Override
    public void edit(Permission permission) {
        wpPermissionsDao.edit(permission);
    }

    @Override
    public void delete(Integer id) {
        wpPermissionsDao.delete(id);
    }

    @Override
    public Integer findPermissionReferencedCount(Integer id) {
        return wpPermissionsDao.findPermissionReferencedCount(id);
    }


}
